package com.yang.webapi.module.service.impl;

import com.yang.security.model.LoginUser;
import com.yang.security.utils.UserUtils;
import com.yang.service.api.AddrService;
import com.yang.service.model.dto.post.AddrPostDTO;
import com.yang.service.model.dto.put.AddrPutDTO;
import com.yang.service.model.vo.AddrVo;
import com.yang.webapi.module.service.AddrWebService;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by xin7k
 * Date: 15:03
 */
@Service
@Slf4j
public class AddrWebServiceImpl implements AddrWebService {

    @Autowired
    AddrService addrService;


    @Override
    public String save(AddrPostDTO dto) {
        String id = UserUtils.getUserId();
        return addrService.save(dto,id);
    }

    @Override
    public List<AddrVo> listAllAddrByUserId() {
        String id = UserUtils.getUserId();
        log.info("id: {}", id);
        LoginUser user = UserUtils.getUser();
        log.info("user: {}", user);
        return addrService.selectList(UserUtils.getUserId());
    }

    @Override
    public boolean deleteAddByAddrId(String addrId) {
        return addrService.deleteById(addrId);
    }

    @Override
    public boolean updateAddrById(String addrId, AddrPutDTO dto) {
        if(UserUtils.getUser() != null){
            return addrService.update(addrId,dto);
        }
        return false;
    }
}
